﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;

namespace Client
{
    public partial class FormConnect : Form
    {
        public FormConnect()
        {
            InitializeComponent();
        }
        private TcpClient tcpClient;
        private bool flagConnected = false;

        private void buttonConnect_Click(object sender, EventArgs e)
        {
            tcpClient = new TcpClient();
            IPEndPoint ipe = new IPEndPoint(IPAddress.Parse(textBoxIP.Text), 1234);
            try
            {
                tcpClient.Connect(ipe);
            }catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return;
            }
            MessageBox.Show("Connection is successfull!","Notify",MessageBoxButtons.OK,MessageBoxIcon.Information);
            this.flagConnected = true;
            this.Close();
        }

        public bool getConnectionStatus()
        {
            return flagConnected;
        }

        public TcpClient getTcpClient()
        {
            return tcpClient;
        }

        public string getServerIP()
        {
            return textBoxIP.Text;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
